package icu.makka.yygh.controller;

import icu.makka.yygh.model.hosp.Hospital;
import icu.makka.yygh.result.Result;
import icu.makka.yygh.service.HospitalService;
import icu.makka.yygh.service.impl.HospitalServiceImpl;
import icu.makka.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Slf4j
@Api(tags = "医院后台管理")
@RestController
@RequestMapping("admin/hosp/hospital")
public class HospitalController {

    @Autowired
    private HospitalServiceImpl hospitalService;

    @ApiOperation(value = "医院详细信息")
    @GetMapping("show/{id}")
    public Result show(@PathVariable String id) {
        log.info("医院详细信息");
        Map<String, Object> map = hospitalService.getHospById(id);
        return Result.ok(map);
    }

    @ApiOperation(value = "更新医院上线状态")
    @GetMapping("updateStatus/{id}/{status}")
    public Result udpateHospStatus(@PathVariable("id") String id,
                                   @PathVariable("status") Integer status) {
        log.info("更新医院上线状态");
        hospitalService.updateStatus(id, status);
        return Result.ok();
    }

    /**
     * 医院列表
     * @param page
     * @param limit
     * @param hospitalQueryVo
     * @return
     */
    @ApiOperation("医院列表查询")
    @GetMapping("list/{page}/{limit}")
    public Result listHosp(@PathVariable("page") Integer page,
                           @PathVariable("limit") Integer limit,
                           HospitalQueryVo hospitalQueryVo) {
        log.info("医院列表，page={}，limit={}", page, limit);
        //调用service层
        Page<Hospital> pageModel = hospitalService.selectHospPage(page, limit, hospitalQueryVo);
        //返回结果
        return Result.ok(pageModel);
    }
}
